package cn.lliiooll.cmd;

import cn.lliiooll.Mentor;
import cn.lliiooll.mt.Confirm;
import cn.lliiooll.mt.ShiFu;
import org.bukkit.Bukkit;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;

public class StCmd implements CommandExecutor  {

    private int time = Mentor.m.getConfig().getInt("cooltime");

    @Override
    public boolean onCommand(CommandSender commandSender, Command command, String s, String[] args) {
        Mentor m = Mentor.m;
        if (!(commandSender instanceof Player)){
            m.error("控制台不能使用指令");
            return true;
        }
        Player p = (Player) commandSender;
        if(args.length == 0){
            m.error("玩家名不能为空",p);
            return true;
        }
        if(Bukkit.getPlayer(args[0]) == null){
            if(Bukkit.getOfflinePlayer(args[0]) != null){
                m.info("玩家未上线",p);
                return true;
            }
            m.info("玩家不存在",p);
            return true;
        }
        if(args[0].equalsIgnoreCase(p.getName())){
            Mentor.m .info("你好自恋啊!!!∑(ﾟДﾟノ)ノ",p);
            return true;
        }
        if(new Confirm().get(Bukkit.getPlayer(args[0]).getUniqueId()) != null){
            Mentor.m .info("你已经有一个请求了!",p);
            return true;
        }
        Confirm.add(Bukkit.getPlayer(args[0]).getUniqueId(),new Object[]{"st",time,p});
        m.info("成功发送请求，等待对方回应",p);
        m.info("玩家" + p.getName() + "想要成为您的师傅,在 &e" + time + "秒 &b内输入/mt confirm 来接受",Bukkit.getPlayer(args[0]));
        return true;
    }
}
